<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>{{ num }}</strong></span
    >
    <ul class="filters">
      <li>
        <a
          @click="selectFn('all')"
          :class="{ selected: isSelect === 'all' }"
          href="javascript:;"
          >全部</a
        >
      </li>
      <li>
        <a
          @click="selectFn('unsucc')"
          :class="{ selected: isSelect === 'unsucc' }"
          href="javascript:;"
          >未完成</a
        >
      </li>
      <li>
        <a
          @click="selectFn('succ')"
          :class="{ selected: isSelect === 'succ' }"
          href="javascript:;"
          >已完成</a
        >
      </li>
    </ul>
    <button @click="clear" v-show="isShow" class="clear-completed">
      清除已完成
    </button>
  </footer>
</template>

<script>
export default {
  data() {
    return {
      isSelect: "all",
    };
  },
  props: ["list"],
  computed: {
    num() {
      return this.list.filter((item) => !item.isDone).length;
    },
    isShow() {
      return this.list.some((item) => item.isDone);
    },
  },
  methods: {
    clear() {
      this.$emit("clearFn");
    },
    selectFn(type) {
      this.isSelect = type;
      this.$emit("selectFn", type);
    },
  },
};
</script>
